package com.artron.mediaartron.ui.fragment.order;

import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.TextView;

import com.artron.baselib.base.BaseLoadingFragment;
import com.artron.baselib.base.BaseStaticFragment;
import com.artron.baselib.entity.Response;
import com.artron.baselib.utils.UIUtils;
import com.artron.mediaartron.R;
import com.artron.mediaartron.data.entity.FrameData;
import com.artron.mediaartron.data.entity.OrderDetailData;
import com.artron.mediaartron.data.net.RetrofitHelper;
import com.artron.mediaartron.data.production.SuitableSizeHelper;
import com.artron.mediaartron.ui.activity.GeneralActivity;

import butterknife.BindView;
import rx.Observable;

import static com.artron.baselib.utils.UIUtils.ColorText.holder;
import static com.artron.baselib.utils.UIUtils.getColor;

/**
 * Class description here
 *
 * @author doing
 * @version 1.0.0
 * @since 2017-10-30.
 */

public class OrderSuccessFragment extends BaseLoadingFragment<OrderDetailData> {

    @BindView(R.id.OrderSuccessFragment_tv_code)
    protected TextView mTvCode;
    @BindView(R.id.OrderSuccessFragment_tv_price)
    protected TextView mTvPrice;
    @BindView(R.id.OrderSuccessFragment_btn_loop_up_order)
    protected Button mBtnLookupOrder;
    @BindView(R.id.OrderSuccessFragment_btn_made)
    protected Button mBtnMade;
    private String mOrderId;

    public static OrderSuccessFragment newInstance(String orderId) {
        OrderSuccessFragment fragment = new OrderSuccessFragment();
        fragment.init(orderId);
        return fragment;
    }

    @Override
    public void onViewCreated(View view, Bundle savedInstanceState) {
        super.onViewCreated(view, savedInstanceState);
        show();
    }

    private void init(String orderId) {
        this.mOrderId = orderId;
    }

    @Override
    protected int getLayoutId() {
        return R.layout.fragment_order_success;
    }

    @Override
    public void initViewWithData(OrderDetailData data) {
        UIUtils.setTextWithColor(mTvPrice,
                holder(getColor(R.color.gray_33), "金额："),
                holder(getColor(R.color.order_purple),
                        String.format("￥%d.00", data.getTotalPrice())));

        mBtnLookupOrder.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                GeneralActivity.start(mContext, GeneralActivity.ORDER_DETAIL,
                        "订单详情", mOrderId);
            }
        });

        mBtnMade.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                getActivity().onBackPressed();
            }
        });
    }

    @Override
    protected Observable<Response<OrderDetailData>> retrofitData() {
        return RetrofitHelper.getOrderApi().queryOrder(mOrderId);
    }

}
